package common.s1

import scala.collection.mutable.ArrayBuffer


/**
  * Created by ikariyui on 2018/3/17.
  */
object HelloScala {

  def main(args: Array[String]): Unit = {


    for( i <- List(1, 2, 3, 4)){
      print(i)
    }
    println()

    //类似join的操作****************
    val v1 = for(i<-1 to 3; j<- 4 to 6)
      print( i + "--" + j + "   ")
    println(v1)

    val v2 = for(i<-1 to 3; j<- 4 to 6)yield{
      print( i + "--" + j + "   ")
      i
    }
    println(v2)

    val v3 = 1.+(2)

    def myfunsub(x:Int,y:Int): Int ={
      x - y
    }

    def myfun2(f:(Int, Int)=>Int): Unit ={
      println(f(5,2))
    }

    myfun2(myfunsub)

    val myfuntest = myfunsub _
    val myfuntest2 = myfun2 _

    val myarray = ArrayBuffer[Int]()

    myarray += (1,2,3,4,5)
    myarray ++= Array(6,7,8,9)

    myarray.insert(0, -1,0)
    myarray.remove(2, 2)

    print(myarray.toBuffer)

    val v4 = for(i <- 0 until 10)yield i

    val arr = ArrayBuffer(1,2,3,4,5,6,7,8,9,10)
    val arr2 = arr.filter(_%2==0).map(_*10)
    println(arr)
    println(arr2)

    val arr3 = Array(1,2,3,4,5)
    arr3.reduce(_+_)
    arr.max
  }

}
